package org.irri.smta.repository;

import java.util.List;

import javax.inject.Named;

import org.irri.smta.domain.SmtaReport;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

@Named("smtaReportRepository")
public interface ISmtaReportRepository extends JpaRepository<SmtaReport, Long>, JpaSpecificationExecutor<SmtaReport> {

	@Transactional(readOnly = true)
	@Query("SELECT o FROM SmtaReport o ORDER BY o.symbol ASC")
	List<SmtaReport> findAllOrdered();
	
	@Transactional(readOnly = true)
	@Query("SELECT o FROM SmtaReport o WHERE o.reportedToTreaty = 0")
	List<SmtaReport> findAllUnreported();
	
	@Transactional(readOnly = true)
	@Query("SELECT o FROM SmtaReport o WHERE o.reportedToTreaty = 1")
	List<SmtaReport> findAllReported();
	
	@Transactional(readOnly = true)
	@Query("SELECT o FROM SmtaReport o WHERE o.symbol = :symbol")
	List<SmtaReport> findBySymbol(@Param("symbol") String symbol);
	
}
